import { http } from '../../utils/request'
import type { ResponseWithPage, Response, PaginatedRequest } from '../type'
import type { BookQueryRequest, BookResponse, VectorStoreRequest } from './type'

export const queryBook = async (
  data: PaginatedRequest<BookQueryRequest>
): Promise<Response<ResponseWithPage<BookResponse>>> => {
  return await http.post('/api/book/query', data)
}

export const deleteBook = async (id: string): Promise<Response> => {
  return await http.delete(`/api/book/delete/${id}`)
}

export const uploadBook = async (
  data: FormData
): Promise<Response<BookResponse>> => {
  return await http.post('/api/book/upload', data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}

export const store = async (data: VectorStoreRequest): Promise<Response> => {
  return await http.post('/ai-api/vector/store', data)
}

export const remove = async (id: string): Promise<Response> => {
  return await http.delete(`/ai-api/vector/remove/${id}`)
}

export const downloadBook = async (
  id: string,
  objName: string
): Promise<any> => {
  return await http.get(
    '/api/book/download',
    { id, objName },
    { responseType: 'blob' }
  )
}
